<?php

/**
 * This is the model class for table "{{image}}".
 *
 * The followings are the available columns in table '{{image}}':
 * @property integer $imageID
 * @property integer $userID
 * @property integer $vendorID
 * @property string $image_type
 * @property integer $image_height
 * @property integer $image_width
 * @property string $image_name
 * @property string $image_extenstion
 * @property string $created
 * @property string $modified
 *
 * The followings are the available model relations:
 * @property User $user
 * @property Vendor $vendor
 */
class Image extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Image the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{image}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('userID, vendorID, image_height, image_width', 'numerical', 'integerOnly'=>true),
			array('image_type, image_extenstion', 'length', 'max'=>45),
			array('image_name', 'length', 'max'=>100),
			array('created, modified', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('imageID, userID, vendorID, image_type, image_height, image_width, image_name, image_extenstion, created, modified', 'safe', 'on'=>'search'),
						array('modified','default',
           	  'value'=>new CDbExpression('NOW()'),
              'setOnEmpty'=>false,'on'=>'update'),
        	array('created,modified','default',
              'value'=>new CDbExpression('NOW()'),
              'setOnEmpty'=>false,'on'=>'insert'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'user' => array(self::BELONGS_TO, 'User', 'userID'),
			'vendor' => array(self::BELONGS_TO, 'Vendor', 'vendorID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'imageID' => 'Image',
			'userID' => 'User',
			'vendorID' => 'Vendor',
			'image_type' => 'Image Type',
			'image_height' => 'Image Height',
			'image_width' => 'Image Width',
			'image_name' => 'Image Name',
			'image_extenstion' => 'Image Extenstion',
			'created' => 'Created',
			'modified' => 'Modified',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('imageID',$this->imageID);
		$criteria->compare('userID',$this->userID);
		$criteria->compare('vendorID',$this->vendorID);
		$criteria->compare('image_type',$this->image_type,true);
		$criteria->compare('image_height',$this->image_height);
		$criteria->compare('image_width',$this->image_width);
		$criteria->compare('image_name',$this->image_name,true);
		$criteria->compare('image_extenstion',$this->image_extenstion,true);
		$criteria->compare('created',$this->created,true);
		$criteria->compare('modified',$this->modified,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	
	public function getValue($type,$arrParams = array())
	{
		switch ($type){
			case 'USER-ID':
				//On the basis of userID it will return higher qualification details
				$objUser = Image::model()->find('userID=?',array($arrParams['userID']));
			return $objUser;
			break;
		}
	}
}